<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateExportDownloadsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('export_downloads', function (Blueprint $table) {
            $table->id();

            $table->string('name', 64)->default('')->comment('文件名称');
            $table->char('ext', 8)->default('')->comment('文件扩展名');
            $table->string('path', 128)->default('')->comment('文件path');
            $table->unsignedInteger('startTime')->default(0)->comment('任务开始执行时间');
            $table->unsignedInteger('completeTime')->default(0)->comment('完成时间');
            $table->unsignedInteger('expireTime')->default(0)->comment('过期时间 0永久');
            $table->tinyInteger('status')->default(0)->comment('0默认 1导出中 2导出完成 3导出异常');
            $table->tinyInteger('client')->default(0)->comment('0默认 1web 2app');
            $table->unsignedSmallInteger('fileType')->default(0)->comment('导出类型(订单明细、支付明细...) 详见枚举');
            $table->json('params')->nullable()->comment('导出涉及参数');

            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('updatedAt')->default(0)->comment('更新时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('更新人');
            $table->tinyInteger('isDeleted')->default(0);

            $table->index(['createdByUid', 'client'], 'idx_createdByUid');

            $table->collation = 'utf8mb4_general_ci';
            $table->comment   = '导出 - 文件下载中心';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('export_downloads');
    }
}
